package com.ldy.demo6;

import org.junit.Test;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * 描述：测试nashorn js，jdk 8 新家的功能<br>
 * 版权：Copyright (c) 2011 ~ 2017<br>
 * 公司：北京活力天汇<br>
 * 作者：刘德咏<br>
 * 版本：1.0<br>
 * 创建日期：2017/8/2<br>
 */
public class NashornDemo {
    public static void main(String[] args) throws ScriptException {
        ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
        ScriptEngine engine = scriptEngineManager.getEngineByName("nashorn");
        engine.eval("load('src/main/java/com/ldy/demo6/hello.js')");
        HelloWorld helloWorld = loadHelloWorld(engine);

    }

    static HelloWorld loadHelloWorld(ScriptEngine engine) throws ScriptException{
        return (HelloWorld) engine.eval("load('src/main/java/com/ldy/demo6/hello.js')");
    }

    @Test
    public void testBreak() {
        for (int i = 0; i< 5; i++) {
            for ( int j=0; j< 5; j++) {
                if (j == 1) {
                    break;
                }
                System.out.println(i + "" + j);
            }
        }
    }

}
